﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class gbookviewcheck : System.Web.UI.Page
{
    public string Classn,straddtime;
	public string gname,gtitle,gdate,gtel,gemail,gip,gaddress,gcontent,gcard,gback;
    protected void Page_Load(object sender, EventArgs e)
    {
		if (!Page.IsPostBack)
        {
            Classn="查看留言";
			string id = Request.QueryString["id"];
            if (!string.IsNullOrEmpty(id))
            {
                HiddenField1.Value = Request.QueryString["id"];
				DataSet ds = Socut.Data.ExecuteDataSet("select * from web_guestbook where id=" + id);
                gname = ds.Tables[0].Rows[0][1].ToString();
				gtitle = ds.Tables[0].Rows[0][2].ToString();
				gdate = ds.Tables[0].Rows[0][8].ToString();
				if (Session["gcard"]!=null){
					if (Session["gcard"].ToString()==ds.Tables[0].Rows[0]["gcard"].ToString())
					{
						gaddress = ds.Tables[0].Rows[0][3].ToString();
						gemail = ds.Tables[0].Rows[0][4].ToString();
						gtel = ds.Tables[0].Rows[0][5].ToString();
						gcontent = ds.Tables[0].Rows[0][7].ToString();
						gback = ds.Tables[0].Rows[0]["gback"].ToString();
						pwdsearch.Visible=false;
					}
					else
					{
						pwdsearch.Visible=true;
					}
				}
				else
				{
						
				}
            }
			else
			{
    			Response.Write("<script>alert('操作错误');history.back();</script>");
				
            }
			
        }
    
    }
	
	protected void Button2_Click(object sender, EventArgs e)
    {
        string gcard = this.txtGcard.Text.ToString();
		int gid=Convert.ToInt32(HiddenField1.Value);
		DataSet ds = null;
        try
        {
           ds = Socut.Data.ExecuteDataSet("select * from web_guestbook where id=" + gid);
        }
        catch(Exception Err)
        {
            CommonFunction.ShowMessage("查看留言时出错！", "gbookviewcheck.aspx?id="+gid+"");
        }
		
		
		
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (gcard == ds.Tables[0].Rows[0]["gcard"].ToString())
            {
                Session["gcard"] = gcard.ToString();
                Session.Timeout = 6000;
                
                Response.Redirect("gbookviewcheck.aspx?id="+gid+"");
				//Response.Write(gcard+""+gcard);
				//Response.End();
            }
            else
            {
                CommonFunction.ShowMessage("查看密码错误！", "gbookviewcheck.aspx?id="+gid+"");
            }
        }
        else
        {

            CommonFunction.ShowMessage("查询有误！", "gbookviewcheck.aspx?id="+gid+"");
        }
    }


    public string htmlstr(string chr)
    {
        if (chr == null)
            return "";
        //chr = chr.Replace("<", "&lt");
        //chr = chr.Replace(">", "&gt");
        chr = chr.Replace("\n", "<br>");
        //chr = chr.Replace("\"", "&quot;");
        //chr = chr.Replace("'", "&#39;");
        //chr = chr.Replace(" ", "&nbsp;");
        chr = chr.Replace("select", "");
        chr = chr.Replace("delete", "");
        chr = chr.Replace("update", "");
        chr = chr.Replace("drop", "");
        //chr = chr.Replace(";", "");
        //chr = chr.Replace("(", "");
        //chr = chr.Replace(")", "");
        chr = chr.Replace("and", "");
        chr = chr.Replace("or", "");
        //chr = chr.Replace("\r", "");
        return (chr);
    }

    static bool IsNumeric(string str)
    {
        if (str == null || str.Length == 0)
            return false;
        foreach (char c in str)
        {
            if (!Char.IsNumber(c))
            {
                return false;
            }
        }
        return true;
    }
}
